package com.slz3.business.module.configManagement.conIndexVideo.service;

import com.slz3.business.frame.enums.ValidFlag;
import com.slz3.business.frame.module.Repositorys;
import com.slz3.business.frame.module.Services;
import com.slz3.business.frame.steward.PageableSteward;
import com.slz3.business.module.configManagement.conIndexVideo.domain.ConIndexVideo;
import com.slz3.business.module.configManagement.conIndexVideo.domain.ConIndexVideoFactory;
import com.slz3.business.module.configManagement.conIndexVideo.steward.ConIndexVideoSpecification;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;

import java.util.*;

@Slf4j
@Service
public class ConIndexVideoServiceImpl implements ConIndexVideoService {

    @Override
    public ConIndexVideo save(ConIndexVideo conIndexVideo) {
        return Repositorys.conIndexVideo.save(ConIndexVideoFactory.initBaseFields(conIndexVideo));
    }

    @Override
    public Page<ConIndexVideo> page(MultiValueMap<String, String> params) {
        Page<ConIndexVideo> conIndexVideoPage = Repositorys.conIndexVideo.findAll(
                ConIndexVideoSpecification.findJoin(params), PageableSteward.extract(params)
        );
        return conIndexVideoPage;
    }

    @Override
    public ConIndexVideo modify(ConIndexVideo conIndexVideoNew) {
        return Repositorys.conIndexVideo.saveAndFlush(ConIndexVideoFactory.initBaseFields(conIndexVideoNew));
    }

    @Override
    public Optional<ConIndexVideo> single(UUID uuid) {
        return Repositorys.conIndexVideo.findById(uuid);
    }

    @Override
    public List<ConIndexVideo> findAllByUuids(Iterable<UUID> uuids) {
        return Repositorys.conIndexVideo.findAllById(uuids);
    }

    @Override
    public List<ConIndexVideo> delete(List<ConIndexVideo> conIndexVideoList) {
        conIndexVideoList.stream().forEach(item -> {
            item.setValidFlag(ValidFlag.DEL);
            ConIndexVideoFactory.initBaseFields(item);
        });
        return Services.conIndexVideoTransactional.batchModify(conIndexVideoList);
    }

}
